using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteAlways]
public class MyGUIToggleGroup : MonoBehaviour
{
    private MyGUIToggle[] toggles;
    private MyGUIToggle frontTog;
    private void Start()
    {
        toggles = GetComponentsInChildren<MyGUIToggle>();

        if (toggles == null) return;
        for (int i = 0; i < toggles.Length; i++)
        {
            MyGUIToggle toggle = toggles[i];
            toggle.ChangeValue += (v) =>
            {
                //当传入的是ture时 需要把另外两个变成false
                if (v)
                {
                    for (int j = 0; j < toggles.Length; j++)
                    {
                        toggles[j].isSel = false;
                    }
                    toggle.isSel = true;

                    frontTog = toggle;
                }
                else if (toggle == frontTog)
                {
                    toggle.isSel = true;
                }
            };
        }
    }
}
